home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_10.lha / 6_10 / 6_10tst3.c < prev    next >
Text File  |  1993-08-08  |  2KB  |  84 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6. include <string.h>
  7. include <values.h>
  8.  
  9. include "lint.h"
  10.  
  11. oid testdiv(LINT A, LINT B)
  12.  
  13.    LINT quot = A / B;
  14.    cout << A << " / " << B << " = " << quot << "\n";
  15.  
  16.  
  17. oid testmod(LINT A, LINT B)
  18.  
  19.    LINT rem = A % B;
  20.    cout << A << " % " << B << " = " << rem << "\n";
  21.  
  22.  
  23. oid testdivmod(LINT A, LINT B)
  24.  
  25.    LINT quot, rem;
  26.    dodivmod(A, B, quot, rem);
  27.    cout << A << " / " << B << " = " << quot << "\n";
  28.    cout << A << " % " << B << " = " << rem << "\n";
  29.  
  30.  
  31. oid testmul(LINT A, LINT B)
  32.  
  33.    LINT prod = A * B;
  34.    cout << A << " * " << B << " = " << prod << "\n";
  35.  
  36.  
  37. oid testadd(LINT A, LINT B)
  38.  
  39.    LINT sum = A + B;
  40.    cout << A << " + " << B << " = " << sum << "\n";
  41.  
  42.  
  43. oid testsub(LINT A, LINT B)
  44.  
  45.    LINT diff = A - B;
  46.    cout << A << " - " << B << " = " << diff << "\n";
  47.  
  48.  
  49. oid testneg(LINT A)
  50.  
  51.    LINT neg = -A;
  52.    cout << " 0, 0 - " << A << " = " << neg << "\n";
  53.  
  54.  
  55. oid testpos(LINT A)
  56.  
  57.    LINT pos = +A;
  58.    cout << " 0, 0 + " << A << " = " << pos << "\n";
  59.  
  60.  
  61. nline int eq(char*s1, char*s2)
  62.  
  63.    return (strcmp(s1, s2) == 0);
  64.  
  65.  
  66. ain()
  67.  
  68.    LINT x = 0, y = 0;
  69.    char op[100];
  70.    while (cin >> x >> op >> y)
  71.        {
  72. if (eq(op, "+")) testadd(x, y);
  73. else if (eq(op, "-")) testsub(x, y);
  74. else if (eq(op, "*")) testmul(x, y);
  75. else if (eq(op, "/")) testdiv(x, y);
  76. else if (eq(op, "%")) testmod(x, y);
  77. else if (eq(op, "/%")) testdivmod(x, y);
  78. else if (eq(op, "--")) testneg(x);
  79. else if (eq(op, "++")) testpos(x);
  80. else cout << "unknown operator\n";
  81. }
  82.    return 0;
  83.  
  84.